<?php
class VariablesBasicType extends AppModel
{
  var $name = 'VariablesBasicType';
  var $useTable = "variables_basic_types";
  var $id = "vbt_id";
  var $primaryKey = "vbt_id";

  function get_variables_group($cond = null)
  {
		$rows = $this->findAll($cond, "vbt_v_id, vbt_bt_id, vbt_is_default, vbt_value", "vbt_v_id, vbt_bt_id", null, 1, null);
		return $rows;
	}

	function get_variables_types_not_default($v_id = 0)
	{
		$q = "select * from wf_variables_basic_types v1, wf_variables ";
		$q .= "where v_id = vbt_v_id and v_id = $v_id and vbt_is_default = 0 ";
		//echo $q;
		$rows = $this->query($q);
		if (!empty($rows))
    {
      return $rows[0][0];
    }
    else
    {
  		$q = "select * from wf_variables_basic_types v1, wf_variables where v_id = vbt_v_id and v_id = $v_id and vbt_is_default = 1 ";
		  $rows = $this->query($q);
		  if (empty($rows)) 
      {
        return array();
      }
      else 
      {
        return $rows[0][0];
      }  
    }
	}

	function getFieldValue($field, $key, $key_value)
	{
		$rows = $this->field($field, array("$key" => "$key_value"));
		return $rows;
  }

  function getFieldsValue($whereArray, $fields)
  {
		$rows = $this->find($whereArray, $fields, null, null);
		return $rows;
  }

  function setPrimaryKey ($key)
  {
    $this->primaryKey = $key;
  }

  function insertData($values)
  {
    $modelName = $this->name;
    return $this->save(array($modelName => $values));
  }
}
?>
